package com.hjl.cookies;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ServivE
 * @version 0.1
 * @className CookiesServlet
 * @description
 * @date 2024/7/25 21:54
 * @since jdk11
 */
@WebServlet("/cs")
public class CookiesServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //服务端创建Cookie对象
        Cookie cookie = new Cookie("username", "huangjinliang");
        Cookie cookie1 = new Cookie("password", "123456");
        //将cookie响应给客户端
        resp.addCookie(cookie);
        resp.addCookie(cookie1);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
